package com.fooddelivery.Mapper;

import com.fooddelivery.Entity.Dish;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 菜品 Mapper 接口
 * </p>
 *
 * @author zhengruiyang
 * @since 2025-08-31
 */
@Mapper
public interface DishMapper extends BaseMapper<Dish> {

    boolean saveOrUpdate(Dish dish);

    @Update("UPDATE dish SET status = CASE WHEN status = 0 THEN 1 ELSE 0 END WHERE id = #{id}")
    boolean updateStatus(Dish dish);

    @Delete("DELETE FROM dish WHERE category_id = #{categoryId}")
    boolean removeByCategoryId(Dish dish);//删除dish表中菜品为分类id的菜品

    void save(Dish dish);

    @Select("SELECT COUNT(*) FROM dish")
    int dishCount();

}
